using BepInEx.Logging;
using System;
using System.Collections.Generic;

namespace VisualmodBep;

public class Log
{
    private static ManualLogSource _log;

    public static bool InfoEnable = true;
    public static List<Action<string>> ErrorActions = new List<Action<string>>();

    public static void OnLoad(string name)
    {
        _log = new ManualLogSource(name);
        Logger.Sources.Add(_log);
    }

    public static void LogInfo(string msg)
    {
        if (InfoEnable)
        {
            _log.LogInfo(msg);
        }
    }

    public static void LogError(string msg)
    {
        _log.LogError(msg);
        foreach (Action<string> action in ErrorActions)
        {
            action(msg);
        }
    }

    public static void OnDestroy()
    {
        Logger.Sources.Remove(_log);
        _log = null;
    }
}